﻿using Core.RabbitMQBus.Common;
using Core.RabbitMQBus.EventBus;
using Core.RabbitMQBus.Log;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace Core.RabbitMQBus.Extensions
{
    public static class ServiceCollectionExtension
    {
        /// <summary>
        /// 注入RabbitMQ
        /// </summary>
        /// <param name="services"></param>
        /// <param name="options"></param>
        public static void RegisterRabbitMQ(this IServiceCollection services, Action<RabbitMQOptions> options)
        {
            services.Configure(options);
            services.AddSingleton<ILoggerHelper, ExceptionLessLogger>();
            services.AddSingleton<IConnectionChannel, ConnectionChannel>();
            services.AddSingleton<ISerializer, SwifterJsonSerializer>();
            services.AddSingleton<IRabbitMqPublisher, RabbitMqPublisher>();
            services.AddSingleton<IRabbitMqSubscriber, RabbitMqSubscriber>();
        }

    }
}
